
public class TestIterator {

    public static void main(String[] args) {

        IBaggageCollection iBaggageCollection = initBaggage();

        System.out.println("当前对象元素个数：" + iBaggageCollection.size() + "个");

        IMyIterator<Baggage> it = iBaggageCollection.iterator();

        while(it.hasNext()) {
            Baggage baggage = it.next();
            System.out.println(baggage.getName());
        } 
    } 

    private static IBaggageCollection initBaggage() {
        IBaggageCollection iBaggageCollection = new BaggageCollectionImpl();
        for (int i=0;i<10;i++){//初始化 10 个箱子进集合等待迭代
            Baggage box = new Baggage("箱子" + (i+1));
            iBaggageCollection.add(box);
        }
        return iBaggageCollection;
    }
}